let KeyPrefix:string = 'xp-'; // 键前缀
let localkeys:string[] = [
    'un', 
    'pwd',
    'island',
    'appList',
    'islandOptions',
    'todoList',
    'noteList',
    'mineBackupAppId',
    'islandStoreData'
];
let sessionkeys:string[] = 
[
    'token', 
    'userData',
    'lnglat',
    'weather',
    'backupId'
];

interface operations {
    key?:string,
    get:()=>void,
    set:(value:any)=>void,
    remove:()=>void
}
// 操作
let operation:operations =
{
    get ()
    {
        const key = `${KeyPrefix}${this.key}`;
        return window.localStorage.getItem(key);
    },
    set (value)
    {
        const key = `${KeyPrefix}${this.key}`;
        window.localStorage.setItem(key, value);
    },
    remove ()
    {
        const key = `${KeyPrefix}${this.key}`;
        window.localStorage.removeItem(key);
    }
};

// 操作
let operation1:operations =
{
    get ()
    {
        const key = `${KeyPrefix}${this.key}`;
        return window.sessionStorage.getItem(key);
    },
    set (value)
    {
        const key = `${KeyPrefix}${this.key}`;
        window.sessionStorage.setItem(key, value);
    },
    remove ()
    {
        const key = `${KeyPrefix}${this.key}`;
        window.sessionStorage.removeItem(key);
    }
};

let CacheService:any = {};

localkeys.forEach((key) =>
{
    CacheService[key] =
      {
          key,
          ...operation
      };
});
sessionkeys.forEach((key) =>
{
    CacheService[key] =
    {
        key,
        ...operation1
    };
});

export default CacheService;